package xyz.zhzby.cyzx.acl.controller;


import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.zhzby.cyzx.acl.dto.request.RolePageRequest;
import xyz.zhzby.cyzx.acl.dto.response.RoleResponse;
import xyz.zhzby.cyzx.acl.entity.Role;
import xyz.zhzby.cyzx.acl.service.IRoleService;
import xyz.zhzby.cyzx.servicebase.domain.PageResponse;
import xyz.zhzby.cyzx.servicebase.domain.RestResponse;

import java.util.List;

/**
 * @author zby
 * @date 2021/12/07
 */
@RestController
@RequestMapping("/acl/role")
//@CrossOrigin
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @ApiOperation(value = "新增角色")
    @PostMapping("")
    public RestResponse<String> save(@RequestBody Role role) {
        return roleService.saveRole(role);
    }

    @ApiOperation(value = "获取角色分页列表")
    @PostMapping("/list")
    public RestResponse<PageResponse<RoleResponse>> index(@RequestBody RolePageRequest rolePageRequest) {
        return roleService.queryRoles(rolePageRequest);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{roleId}")
    public RestResponse<RoleResponse> getOneById(@PathVariable("roleId") Long roleId) {
        return roleService.getOneById(roleId);
    }

    @ApiOperation("修改角色")
    @PutMapping("")
    public RestResponse<String> updateOne(@RequestBody Role role) {
        return roleService.updateOne(role);
    }

    @ApiOperation("删除角色")
    @DeleteMapping("/{roleId}")
    public RestResponse<String> removeRole(@PathVariable("roleId") Long roleId) {
        return roleService.removeRole(roleId);
    }

    @ApiOperation("批量删除角色")
    @DeleteMapping("/list")
    public RestResponse<String> removeRoleBatch(@RequestBody List<Long> ids) {
        return roleService.removeRoleBatch(ids);
    }
}

